package com.chem.lems.controller;

import com.chem.lems.entity.Role;
import com.chem.lems.serves.RoleServies;
import com.chem.lems.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleServies roleServies;

    /**
     * 获取左侧菜单数据
     *
     * @return
     */
    @GetMapping("/tree/{roleId}")
    public ResultUtil gitMenusTree(@PathVariable("roleId") String roleId) {

        return roleServies.tree(roleId);
    }

    /**
     * 获取角色信息
     *
     * @return
     */
    @GetMapping()
    public ResultUtil gitRoles() {
        return roleServies.gitRoles();
    }

    /**
     * 根据角色ID查询角色信息
     *
     * @return
     */
    @GetMapping("info/{roleId}")
    public ResultUtil gitRoleInfo(@PathVariable("roleId") String roleId) {
        return roleServies.gitRoleInfo(roleId);
    }

    /**
     * 删除角色对应的权限
     *
     * @param roleId
     * @param rightId
     * @return
     */
    @DeleteMapping("{roleId}/{rightId}")
    public ResultUtil deleteById(@PathVariable("roleId") String roleId, @PathVariable("rightId") int rightId) {
        return roleServies.deleteMenus(roleId, rightId);
    }

    /**
     * 删除角色
     *
     * @param roleId
     * @return
     */
    @DeleteMapping("{roleId}")
    public ResultUtil deleteRole(@PathVariable("roleId") String roleId) {
        return roleServies.deleteRole(roleId);
    }


    /**
     * 给角色授权功能
     *
     * @param roleId
     * @param rids
     * @return
     */
    @PostMapping("{roleId}")
    public ResultUtil roleAuthorization(@PathVariable("roleId") String roleId, @RequestBody() Integer[] rids) {
        return roleServies.roleAuthorization(roleId, rids);
    }

    /**
     * 添加新角色
     *
     * @param role
     * @return
     */
    @PostMapping("add")
    public ResultUtil addRole(@RequestBody Role role) {
        return roleServies.addRole(role);

    }

    @PutMapping()
    public ResultUtil editRoleInfo(@RequestBody Role role) {
        return roleServies.editRoleInfo(role);
    }
}
